package com.hdwmw;
import android.support.v4.app.FragmentActivity;

//import com.slidingmenu.lib.SlidingMenu;

public class AttachExample extends FragmentActivity {

	/*private SlidingMenu menu;
	static View v;
	
	Handler handler = new Handler() {

		@Override
		public void handleMessage(Message msg) {
			if(msg.what == 0) {
				if(menu != null) {
//					SlidingActivityHelper help = new SlidingActivityHelper(AttachExample.this);
					menu.setMode(SlidingMenu.LEFT_RIGHT);
					menu.setBehindScrollScale(0f);
					menu.setBehindWidth(720);
					menu.setShadowDrawable(null);
					menu.setFadeEnabled(false);
					
//					menu.setSecondaryMenu(R.layout.menu_frame_two);
					getSupportFragmentManager()
					.beginTransaction()
					.replace(R.id.menu_frame_two, new SampleListFragment(handler))
					.commit();
					
//					v = AttachExample.this.getWindow().getDecorView().findViewById(android.R.id.content);
//					v = ((ViewGroup)getWindow().getDecorView());
//					((ViewGroup)getWindow().getDecorView()).removeViewAt(0);
//					v = findViewById(android.R.id.content);
					menu.requestLayout();
					
//					Intent i = new Intent(AttachExample.this, MyActivty.class);
//					startActivity(i);
				}
			}
			super.handleMessage(msg);
		}
	};

	Bundle savedInstanceState;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.savedInstanceState = savedInstanceState;

		// set the Above View
		setContentView(R.layout.content_frame);
		getSupportFragmentManager()
		.beginTransaction()
		.replace(R.id.content_frame, new SampleListFragment(null))
		.commit();

		// configure the SlidingMenu
		menu = new SlidingMenu(this);
		menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
		menu.setBehindScrollScale(0f);
		menu.setBehindWidth(720);
		menu.setShadowDrawable(null);
		menu.setFadeEnabled(false);
		menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
		menu.setMenu(R.layout.menu_frame);
		
		Intent intent = new Intent(this, ServiceTurnOver1.class);
		intent.putExtra("service", "清洗");
		intent.putExtra("typeID", "1");
		intent.putExtra("serviceID", "1");
		View v = activityToView("service", intent);
		
		getSupportFragmentManager()
		.beginTransaction()
		.replace(R.id.menu_frame, new SampleListFragment(v))
		.commit();
		
		menu.showMenu();
		
		MyBroad my = new MyBroad();
		IntentFilter fil = new IntentFilter();
		fil.addAction("com.my");
		registerReceiver(my, fil);
	}

	@Override
	public void onBackPressed() {
		if (menu.isMenuShowing()) {
			menu.showContent();
		} else {
			super.onBackPressed();
		}
	}
	
	public View activityToView(String tagName,Intent intent) {
        LocalActivityManager lam = new LocalActivityManager(AttachExample.this, true);
        lam.dispatchCreate(savedInstanceState);
        
        Window window = lam.startActivity(tagName, intent);
        View view = window != null ? window.getDecorView() : null;
        if(view != null) {
            view.setVisibility(View.VISIBLE);
            view.setFocusableInTouchMode(true);
            ((ViewGroup)view).setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
        }
        return view;
    }

	
	class MyBroad extends BroadcastReceiver {

		@Override
		public void onReceive(Context context, Intent intent) {
			Intent i = new Intent(AttachExample.this, MerchantTurnActivity1.class);
			String siteID = intent.getStringExtra("siteID");
			int position = intent.getIntExtra("sitePosition",0);
			String modern = intent.getStringExtra("modern");
			if(modern != null && modern.equals("menu")) {
				menu.showMenu();
			} else {
				i.putExtra("siteID", siteID);
				i.putExtra("sitePosition", position);
				View v = activityToView("me", i);
				getSupportFragmentManager()
				.beginTransaction()
				.replace(R.id.content_frame, new SampleListFragment(v))
				.commit();
				menu.requestLayout();
				menu.showContent();
			}
			
		}
		
	}*/
}
